package com.ymatou.iapi.fundstrategy.parameter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;



public class FundStrategy {

	public static FundStrategyCreateBean fundStrategyCreate(int strategyType,String beginDate,int strategyLevelType,int userId,String userLoginId,String dimensionId1,String dimensionId2,String dimensionId3) throws Exception {
	    try {
	    	FundStrategyCreateBean fundstrategycreateBean=new FundStrategyCreateBean();
			
			String endDate =YMTDateUtil.getBeforeOrNextDay(100);
			String identityId = Integer.toString(TestDataManager.uniform(200000000));
			FundStrategyinfo fundStrategyinfo=new FundStrategyinfo();
			//FundStrategy 第一层
			fundstrategycreateBean.setFundStrategy(fundStrategyinfo);
				//第二层
				fundStrategyinfo.setStrategyType(strategyType);	//策略类型
				fundStrategyinfo.setStrategyVaildBeginDate(beginDate);
				fundStrategyinfo.setStrategyVaildEndDate(endDate);
				fundStrategyinfo.setStrategyStatus(1);
				fundStrategyinfo.setStrategyLevelType(strategyLevelType);
				fundStrategyinfo.setStrategyAmount(new BigDecimal(0.05).setScale(2,BigDecimal.ROUND_HALF_UP));
				fundStrategyinfo.setStrategyMaxAmount(new BigDecimal(500));
				fundStrategyinfo.setStrategyMinAmount(new BigDecimal(20));
				fundStrategyinfo.setStrategyWeight(new BigDecimal(10));
				fundStrategyinfo.setUserId(userId);
				fundStrategyinfo.setUserLoginId(userLoginId);

				//新建策略列表
				List<StrategyDetail> sList = new ArrayList<StrategyDetail>();
				
				//商品类目维度策略
			if (dimensionId1 != null)
			{
				StrategyDetail s1 = new StrategyDetail();
				s1.setDimensionId(dimensionId1);
				s1.setStrategyDimensionIdentityId(Integer.toString(Integer.valueOf(identityId)+1));
				s1.setStrategyDimensionIdentityName("功能箱包"+TestDataManager.uniform(1000000));	
				sList.add(s1);
			}
			
				//价格区间维度策略
			if (dimensionId2 != null)
			{
				StrategyDetail s2 = new StrategyDetail();
				s2.setDimensionId(dimensionId2);				
				s2.setStrategyDimensionBeginRange(new BigDecimal(TestDataManager.uniform(100)).add(new BigDecimal(2)));
				s2.setBeginRangeInclude(true);
				s2.setStrategyDimensionEndRange(new BigDecimal(TestDataManager.uniform(1000)).add(new BigDecimal(102)));
				s2.setEndRangeInclude(false);
				sList.add(s2);
			}
			
				//国家维度策略
			if (dimensionId3 != null)
			{
				StrategyDetail s3 = new StrategyDetail();
				s3.setDimensionId(dimensionId3);
				s3.setStrategyDimensionIdentityId(identityId);
				s3.setStrategyDimensionIdentityName("国家"+TestDataManager.uniform(100000000));
				sList.add(s3);
			}
				
				//把策略列表加入到参数中
				fundStrategyinfo.setStrategyDetailList(sList);
	    	
	    	return fundstrategycreateBean;
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  
	    return null;
	}
	
	public static FundStrategyCreateBean fundStrategyCreatefornoCountry(String beginDate,int strategyLevelType,String dimensionId1, String dimensionId2, String dimensionId3, BigDecimal beginRange, BigDecimal endRange,String identityId) throws Exception {
	    try {
	    	FundStrategyCreateBean fundstrategycreateBean=new FundStrategyCreateBean();

			String endDate =YMTDateUtil.getBeforeOrNextDay(100);
			
			FundStrategyinfo fundStrategyinfo=new FundStrategyinfo();
			//FundStrategy 第一层
			fundstrategycreateBean.setFundStrategy(fundStrategyinfo);
				//第二层
				fundStrategyinfo.setStrategyType(1);	//策略类型 1收佣 2退佣 3返佣
				fundStrategyinfo.setStrategyVaildBeginDate(beginDate);
				fundStrategyinfo.setStrategyVaildEndDate(endDate);
				fundStrategyinfo.setStrategyStatus(1);
				fundStrategyinfo.setStrategyLevelType(strategyLevelType); //1特殊策略 2全局策略
				fundStrategyinfo.setStrategyAmount(new BigDecimal(0.05).setScale(2,BigDecimal.ROUND_HALF_UP));
				fundStrategyinfo.setStrategyMaxAmount(new BigDecimal(500));
				fundStrategyinfo.setStrategyMinAmount(new BigDecimal(20));
				fundStrategyinfo.setStrategyWeight(new BigDecimal(10));
				fundStrategyinfo.setUserId(112233);
				fundStrategyinfo.setUserLoginId("自动化测试");

				//新建策略列表
				List<StrategyDetail> sList = new ArrayList<StrategyDetail>();
				
				//商品类目维度策略
			if (dimensionId1 != null)
			{
				StrategyDetail s1 = new StrategyDetail();
				s1.setDimensionId(dimensionId1);
				s1.setStrategyDimensionIdentityId(Integer.toString(Integer.valueOf(identityId)+1));
				s1.setStrategyDimensionIdentityName("功能箱包"+TestDataManager.uniform(1000000));	
				sList.add(s1);
			}
				//价格区间维度策略
			if (dimensionId2 != null)
			{
				StrategyDetail s2 = new StrategyDetail();
				s2.setDimensionId(dimensionId2);				
//				s2.setStrategyDimensionBeginRange(new BigDecimal(TestDataManager.uniform(100)).add(new BigDecimal(2)));
				s2.setStrategyDimensionBeginRange(beginRange);
				s2.setBeginRangeInclude(true);
//				s2.setStrategyDimensionEndRange(new BigDecimal(TestDataManager.uniform(1000)).add(new BigDecimal(102)));
				s2.setStrategyDimensionEndRange(endRange);
				s2.setEndRangeInclude(false);
				sList.add(s2);
			}
				//国家维度策略
			if (dimensionId3 != null)
			{
				StrategyDetail s3 = new StrategyDetail();
				s3.setDimensionId(dimensionId3);
				s3.setStrategyDimensionIdentityId(identityId);
				s3.setStrategyDimensionIdentityName("国家"+TestDataManager.uniform(100000000));
				sList.add(s3);
			}
				//把策略列表加入到参数中
				fundStrategyinfo.setStrategyDetailList(sList);
	    	
	    	return fundstrategycreateBean;
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  
	    return null;
	}
	
}
